<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateItemRequestItemsTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('item_request_items', function($table){
			$table->increments('pk');
			$table->integer('request_fk')->unsigned();
			$table->integer('request_type_fk')->unsigned();
			$table->integer('request_item_status_fk')->unsigned();
			$table->integer('amount')->unsigned();
			$table->integer('item_fk')->unsigned();
			$table->string('comment');
			$table->timestamps();
		});

		Schema::table('item_request_items', function($table){
			$table->foreign('request_fk')->references('pk')->on('item_requests');
			$table->foreign('item_fk')->references('pk')->on('items');
			$table->foreign('request_type_fk')->references('pk')->on('item_request_types');
			$table->foreign('request_item_status_fk')->references('pk')->on('item_request_item_status');
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::table('item_request_items', function($table){
			$table->dropForeign('item_request_items_request_fk_foreign');
			$table->dropForeign('item_request_items_item_fk_foreign');
			$table->dropForeign('item_request_items_request_type_fk_foreign');
			$table->dropForeign('item_request_items_request_item_status_fk_foreign');
		});
		echo "item_request_items table relationships removed\n";
		Schema::drop('item_request_items');
		echo "item_request_items table deleted\n";
	}

}
